Improve error for dependencies that don't have the same source path for all build...
authorBryant Mairs <bryant@mai.rs>
Thu, 26 Jan 2017 01:18:19 +0000 (17:18 -0800)
committerBryant Mairs <bryant@mai.rs>
Thu, 26 Jan 2017 01:20:41 +0000 (17:20 -0800)
src/cargo/util/toml.rs
tests/bad-config.rs

index 2a70feecbb3bd71d869ee58a7b2b3ed16836715b..704557f1a845dbe328b678977e8d4cc517f817e2 100644 (file)
@@ -636,8 +636,9 @@ impl TomlManifest {
                 let name = dep.name();
                 let prev = names_sources.insert(name, dep.source_id());
                 if prev.is_some() && prev != Some(dep.source_id()) {
-                    bail!("found duplicate dependency name {}, but all \
-                           dependencies must have a unique name", name);
+                    bail!("Dependency '{}' has different source paths depending on the build \
+                           target. Each dependency must have a single canonical source path \
+                           irrespective of build target.", name);
                 }
             }
         }
index fd22ea3f6f621ed15e2e26996af7c2f44d53d93f..63aae50dfa4763f2d551388b8072c8074085aeb1 100644 (file)
@@ -553,7 +553,53 @@ fn duplicate_deps() {
 [ERROR] failed to parse manifest at `[..]`
 
 Caused by:
-  found duplicate dependency name bar, but all dependencies must have a unique name
+  Dependency 'bar' has different source paths depending on the build target. Each dependency must \
+have a single canonical source path irrespective of build target.
+"));
+}
+
+#[test]
+fn duplicate_deps_diff_sources() {
+    let foo = project("foo")
+    .file("shim-bar/Cargo.toml", r#"
+       [package]
+       name = "bar"
+       version = "0.0.1"
+       authors = []
+    "#)
+    .file("shim-bar/src/lib.rs", r#"
+            pub fn a() {}
+    "#)
+    .file("linux-bar/Cargo.toml", r#"
+       [package]
+       name = "bar"
+       version = "0.0.1"
+       authors = []
+    "#)
+    .file("linux-bar/src/lib.rs", r#"
+            pub fn a() {}
+    "#)
+    .file("Cargo.toml", r#"
+       [package]
+       name = "qqq"
+       version = "0.0.1"
+       authors = []
+
+       [target.i686-unknown-linux-gnu.dependencies]
+       bar = { path = "shim-bar" }
+
+       [target.x86_64-unknown-linux-gnu.dependencies]
+       bar = { path = "linux-bar" }
+    "#)
+    .file("src/main.rs", r#"fn main () {}"#);
+
+    assert_that(foo.cargo_process("build"),
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Dependency 'bar' has different source paths depending on the build target. Each dependency must \
+have a single canonical source path irrespective of build target.
 "));
 }